var currDay = '',
	nextDay = '';
mui.init({
	swipeBack: false
});
mui.plusReady(function() {
	plus.navigator.setStatusBarBackground('#24af96');
	plus.navigator.setStatusBarStyle('light');
	// var today = '2021-04-30';//getTodayStr();
	var today = getTodayStr();
	currDay = today
	resetTitle();
	var operation = plus.webview.create(
		"operation.html",
		"operation", {
			width: '100%',
			height: '100%',
			left: '0px',
			right: '0px',
			top: '44px',
			bottom: '0px',
			zindex: 10,
			margin: 'auto',
			opacity: 1,
			mask: 'none',
			bounce: 'none',
			scalable: true,
		}, {
			dayStr: currDay
		}
	);
	operation.show();
	operation.id = 'operation';
	getNextNormalDay(today);
	mui.back = function() {
		console.log('back');
		plus.navigator.setStatusBarBackground('#fff')
		plus.navigator.setStatusBarStyle('dark');
		var operationDate = plus.webview.getWebviewById('operationDate');
		if (operationDate) {
			operationDate.close();
		}
		var Ophtml = plus.webview.getWebviewById('operation');
		if(Ophtml){
			Ophtml.close();
		}
		plus.webview.currentWebview().close();
	}
	var refeshBtn = document.getElementById('refeshBtn');
	refeshBtn.addEventListener('tap', refreshBtnTapped);
	var titleDom = document.getElementById('title');
	titleDom.addEventListener('tap', selectYearMonthDay);
});

function refreshBtnTapped() {
	var Ophtml = plus.webview.getWebviewById('operation');
	if(Ophtml){
		Ophtml.evalJS('reloadChild("' + currDay + '")');
	}
	var operationDate = plus.webview.getWebviewById('operationDate');
	operationDate.hide();
}

function resetTitle() {
	var dayArr = currDay.split('-')
	var chinDay = dayArr[0] + '年' + dayArr[1] + '月' + dayArr[2] + '日'
	var titleDom = document.getElementById('title');
	titleDom.innerText = chinDay;
}

function selectYearMonthDay() {
	var operationDate = plus.webview.getWebviewById('operationDate');
	if (!operationDate) {
		mui.toast('请重试')
	}
	if (operationDate.isVisible()) {
		operationDate.hide();
		return;
	}
	operationDate.evalJS('pickerShow()');
	operationDate.show();
}

function changeDate(dateStr) {
	currDay = dateStr;
	refreshBtnTapped();
	resetTitle();
}

function getNextNormalDay(todayStr) {
	var pdict = {'parr':todayStr}
	var paramDict = {'method':'web.INMOutInterface:checkHoliday',
		'params':JSON.stringify(pdict),'type':'Method'}
	mui.DHCWebService(paramDict, function(result) {
		plus.nativeUI.closeWaiting();
		console.log(JSON.stringify(result));
		if (result.msgcode != '1') {
			return
		}
		nextDay = result.msg
		if (nextDay == "") {
			nextDay = getNextDay(todayStr)
		}
		initOperationDate()
	}, function(error) {
		nextDay = getNextDay(todayStr)
		initOperationDate()
	});
}

function initOperationDate() {
	var top = 'auto'
	if (plus.os.name == "Android") {
		top = (screen.height - 280) + 'px'
	}
	var operationDate = plus.webview.create(
		"operationDate.html",
		"operationDate", {
			width: '100%',
			height: '280px',
			left: '0px',
			right: '0px',
			top: top,
			bottom: '0px',
			zindex: 11,
			margin: 'auto',
			opacity: 1,
			mask: 'none',
			bounce: 'none',
			scalable: true,
		}, {
			nextDay: nextDay,
			parentWeb: plus.webview.currentWebview()
		}
	);
}

function backEvent(){
	mui.back()
}